//
//  UserViewController.m
//  享动
//
//  Created by darker on 16/4/9.
//  Copyright © 2016年 HHUI. All rights reserved.
//

#import "UserViewController.h"

@interface UserViewController () <UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

// 左边label
@property (nonatomic, strong) UILabel *leftLabel;

// 右边label
@property (nonatomic, strong) UILabel *rightLabel;

@property (nonatomic, strong) UIImageView *headImageView;

@end

@implementation UserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _tableView.frame = CGRectMake(0, 0, KWIDTH, KHEIGHT - 64);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(KWIDTH - 70, 5, 40, 40)];
    _headImageView.backgroundColor = [UIColor grayColor];
    _headImageView.layer.cornerRadius = 20;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 1;
    }
    else if (section == 1)
    {
        return 4;
    }
    else if (section == 2)
    {
        return 2;
    }
    return 0;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _leftLabel = [[UILabel alloc] init];
    _rightLabel = [[UILabel alloc] init];
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            [self setCellWithLeftLabel:@"更换头像" rightLabel:nil];
            _headImageView.image = [UIImage imageNamed:@""];
            [cell addSubview:_leftLabel];
            [cell addSubview:_headImageView];
        }
    }
    if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            [self setCellWithLeftLabel:@"昵称" rightLabel:@"那一年的憧憬"];
        }
        else if (indexPath.row == 1)
        {
            [self setCellWithLeftLabel:@"性别" rightLabel:@"男"];
        }
        else if (indexPath.row == 2)
        {
            [self setCellWithLeftLabel:@"生日" rightLabel:@"请输入生日信息"];
        }
        else if (indexPath.row == 3)
        {
            [self setCellWithLeftLabel:@"所在地" rightLabel:@"福建 福州"];
        }
        [cell addSubview:_leftLabel];
        [cell addSubview:_rightLabel];
    }
    if (indexPath.section == 2)
    {
        if (indexPath.row == 0)
        {
            [self setCellWithLeftLabel:@"介绍" rightLabel:nil];
        }
        [cell addSubview:_leftLabel];
    }
    
    return cell;
}

- (void)setCellWithLeftLabel:(NSString *)leftLabelText
                  rightLabel:(NSString *)rightLabelText
{
    _leftLabel.frame = CGRectMake(10, 15, 150, 20);
    _leftLabel.text = leftLabelText;
    _leftLabel.font = [UIFont systemFontOfSize:14];
    _leftLabel.textColor = [UIColor grayColor];

    _rightLabel.frame = CGRectMake(KWIDTH - 150, 15, 140, 20);
    _rightLabel.font = [UIFont systemFontOfSize:14];
    _rightLabel.textColor = [UIColor grayColor];
    _rightLabel.text = rightLabelText;
    _rightLabel.textAlignment = NSTextAlignmentRight;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
